<!DOCTYPE html>
<html>

<head>
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="zh-CN">
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <meta name="keywords" content="关键词" />
    <meta name="description" content="页面简介" />
    <link rel="icon" href="favicon.ico" />
    <link rel="shortcut icon" href="favicon.ico" />
    <link href="csaa/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="./csaa/fonts/iconfont/iconfont.css">
    <link rel="stylesheet" href="./csaa/fonts/materialicons/material-icons.css">

    <script language="javascript" type="text/javascript" src="./csaa/js/jquery.min.js"></script>
    <script src="./csaa/js/httpPath.js"></script>
    <script src="./csaa/js/httpUtils.js"></script>
    <script language="javascript" type="text/javascript" src="./csaa/js/site.js"></script>
    <title>全国青少年航空科学素质等级考试</title>
</head>

<body class="login" style="background-image:url(./csaa/img/login_bj.jpg);background-color: #01375d;">
    <!-- 头部 开始 -->
    <div class="header login_header ">

    </div>
    <!-- 头部 结束 -->




    <!-- 主体 开始 -->
    <div id="login_main">
        <div class="login_content">
            <div class="part wel_wrap">
                <div class="wel_box">
                    <div class="title">欢迎登录</div>
                    <div class="subtitle">全国青少年航空科学素质等级考试</div>
                </div>
            </div>
            <div class="part form_wrap">
                <div class="form_box">
                    <div class="account_tab" style="display: flex; margin-bottom: 15px; margin-left: -5px; margin-right: -5ox;">
                        <div class="tab_item active" data-sort="student">考生</div>
                        <div class="tab_item" data-sort="teacher">教师</div>
                        <div class="tab_item" data-sort="referee">裁判</div>
                        <div class="tab_item" data-sort="examin">考点</div>
                        <!-- <div class="tab_item" data-sort="censor">专家</div>
                        <div class="tab_item" data-sort="superadmin">超管</div> -->
                        <input type="hidden" value="student" name="account_tab">
                        <input type="hidden" value="" name="codeid">
                    </div>
                    <form id="login_form" autocomplete="off">
                        <label class="form_item form_item_plane">
					  <div class="form_item_con">
						<input type="text" class="form_input" name="account_number" placeholder="用户名" value="" onkeyup="value=value.replace(/[\u4e00-\u9fa5]/ig,'')">
					  </div>
					</label>
                        <label class="form_item form_item_plane">
					  <div class="form_item_con">
						<input type="password" class="form_input" name="password" placeholder="密码" value="">
					  </div>
					</label>
                        <label class="form_item form_item_plane form_item_code">
					  <div class="form_item_con">
						<input type="text" class="form_input" name="code" placeholder="验证码" value="">
						<a class="change_captchas input-group-addon" title="换一张" href="javascript:void(0)"><img class="verifyimg change_code" alt="点击显示" src=""></a>
					  </div>
					</label>
                        <div class="manage_wrap">
                            <a id="btn_login" class="btn btn_color_1 btn_login">登录</a>
                            <div class="reg_wrap">
                                <a class="btn  btn_forget" href="./retrieve_password.html">忘记密码?</a><a class="reg_go" href="./register_kaosheng.html">考生注册</a>
                            </div>
                            <!-- <div class="manage_go"><a href="./login.html">考生登录</a></div> -->
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="footer">@ 全国青少年航空科学素质等级考试</div>

    </div>
    <!-- 主体 结束 -->


    <script>
        //默认传时间戳
        var timestamp = (new Date()).getTime();
        var params = {
            "codeId": timestamp
        }
        $('[name=codeid]').val(timestamp);
        $.ajax({
            url: GET_IMG_CODE,
            data: params,
            type: "POST",
            dataType: "JSON",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success: function(data, textStatus) {
                if (typeof data != "object") {
                    data = JSON.parse(data);
                }
                if (data.status == 1) {
                    $(".change_code").attr("src", data.data);
                }
            },
            error: function(xhr, textStatus, errorThrown) {

            }
        });



        //默认验证图片
        // $.post(GET_IMG_CODE, params, function(results){
        // 	console.log(results)

        // 	$(".change_code").attr("src", results);

        // },'json')

        //换一张
        $(".change_captchas").on('click', function() {
            var timestamp = (new Date()).getTime();
            var params = {
                "codeId": timestamp
            }
            $.post(GET_IMG_CODE, params, function(data) {

                //console.log(data.data)
                if (data.status == 1) {
                    $('.change_code').attr('src', data.data);
                    $('[name=codeid]').val(timestamp);
                }

            }, 'json')

        });

        //账号切换
        $(document).on("click", ".account_tab .tab_item", function() {
            $(this).addClass("active").siblings(".tab_item").removeClass("active");

            if ($(this).data("sort") == "student") { //考生注册
                $(".reg_wrap .reg_go").attr("href", "./register_kaosheng.html").text("考生注册");
            }
            if ($(this).data("sort") == "teacher") { //讲师注册
                $(".reg_wrap .reg_go").attr("href", "./register_jiaoshi.html").text("教师注册");
            }
            if ($(this).data("sort") == "referee") { //裁判注册
                $(".reg_wrap .reg_go").attr("href", "./register_caipan.html").text("裁判注册");
            }
            if ($(this).data("sort") == "examin") { //考点注册
                $(".reg_wrap .reg_go").attr("href", "./register_kaodian.html").text("考点注册");
            }

            $("[name=account_tab]").val($(this).data("sort"));
        });

        //判断相应角色 选择
        // $(".tab_item").each(function(){
        // 	console.log($(this).attr("data-sort"))
        // 	if($(this).attr("data-sort") == "teacher"){
        // 		$(this).trigger("click");
        // 	}
        // });

        //登录
        $(document).keyup(function(event) { //回车事件
            if (event.keyCode == 13) {
                $("#btn_login").trigger("click");
            }
        });
        $("#btn_login").on('click', function() {

            var codeid = $('[name=codeid]').val(); //时间
            var account_number = $("[name=account_number]"); //用户名
            var password = $("[name=password]"); //密码
            var code = $("[name=code]"); //验证码

            if (!account_number.val()) {
                $.fn.winktips("请输入账号");
                account_number.focus();
                return false;
            }
            if (!password.val()) {
                $.fn.winktips("请输入密码");
                password.focus();
                return false;
            }
            if (!code.val()) {
                $.fn.winktips("请输入验证码");
                code.focus();
                return false;
            }
            //var params = $("#login_form").serialize();
            var params = {
                    "roleCode": $("[name=account_tab]").val(), //角色
                    "userName": account_number.val(), //用户名
                    "passWord": password.val(), //密码
                    "code": code.val(), //验证码
                    "codeId": codeid //时间
                }
                //console.log(params)
            $.post(GET_LOGIN, params, function(data) {

                if (data.status == 1) {

                    var page_token = data.data.token;
                    var page_user = data.data.userName;
                    var page_id = data.data.id;
                    var page_roleCode = $("[name=account_tab]").val();
                    var page_roleId = data.data.roleId;

                    if (window.localStorage) {

                        localStorage.setItem("token", data.data.token); //token
                        localStorage.setItem("userName", data.data.userName); //账号
                        localStorage.setItem("userId", data.data.id); //用户id
                        localStorage.setItem("id", data.data.roleId); //角色id
                        localStorage.setItem("roleCode", $("[name=account_tab]").val()); //用户角色id

                    } else {

                        $.cookie("token", data.data.token, {
                            expires: 700
                        });
                        $.cookie("userName", data.data.userName, {
                            expires: 700
                        });
                        $.cookie("userId", data.data.id, {
                            expires: 700
                        });
                        $.cookie("id", data.data.roleId, {
                            expires: 700
                        });
                        $.cookie("roleCode", $("[name=account_tab]").val(), {
                            expires: 700
                        });
                    }

                    location.replace(page_baseurl + "/#/sso?userid=" + page_id + "&token=" + page_token + "&name=" + page_user + "&rolecode=" + page_roleCode + "&id=" + page_roleId); //或进入相应控制台

                } else {
                    $.fn.poptips(data.msg);
                }
            }, 'json');


        });
    </script>
</body>

</html>
